package com.hdax.dm.controller;

import com.hdax.dm.common.utils.CommonResponse;
import com.hdax.dm.common.utils.ResponseUtil;
import com.hdax.dm.exceptions.OrderException;
import com.hdax.dm.service.SubmitOrderService;
import com.hdax.dm.vo.SubmitOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(path = "/p/order/")
public class SubmitOrderController {

    @Autowired
    private SubmitOrderService submitOrderService;
    @PostMapping(path = "/submitorder")
    public CommonResponse<Map<String,String>> submitorder(HttpServletRequest request, @RequestBody SubmitOrderVo vo){
        // 分布式事务
        //beign transaction
        //1. 订单数据库订单表（dm_order）新增数据
        String orderNo = submitOrderService.addOrder(vo,request.getHeader("token"));
        //TODO: 2. 订单数据库订单表（dm_order）修改数据（aliTradeNo, orderType(-1取消、超时；2已支付)）
        //3. 订单数据库订单联系人（dm_order_link_user） 数据新增 订单新增同时已完成

        //4. 排期数据库座位信息表（dm_scheduler_seat）数据修改（orderNo, userId, status(1<->2  1<->3)）


        // rollback
        //commit
        Map<String, String> result = new HashMap<>();
        result.put("orderNo",orderNo);
        return ResponseUtil.returnSuccess(result);
    }
}
